package com.hyst.web;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.hyst.common.ResultBean;
import com.hyst.common.ResultPage;
import com.hyst.domain.Level;
import com.hyst.service.LevelService;

/**
 * @Description:课程级别controller
 * @author：dy 
 *@Date：2018年08月26日
 */
@RestController
@RequestMapping("levels")
@CrossOrigin(maxAge = 3600, origins = "*")
public class LevelController {
	@Autowired
	private LevelService levelService;
	
	@GetMapping
	public ResultPage<Level> getProjects(Level level) {
		return ResultPage.success(levelService.list(level));
	}

	@PostMapping
	public ResultBean<Level> creat(final Level level) {
		return ResultBean.success(levelService.insert(level));
	}

	/**
	 * @Description: 根据主键查询
	 * @param uniqueid
	 * @return ResultBean<Level>
	 */
	@GetMapping("{uniqueid}")
	public ResultBean<Level> getByPriKey(@PathVariable("uniqueid") final String uniqueid) {
		return ResultBean.success(levelService.getByPriKey(uniqueid));
	}

	/**
	 * @Description: 根据主键更新全字段
	 * @param level
	 * @return ResultBean<Level>
	 */
	@PatchMapping("{uniqueid}")
	public ResultBean<Level> update(final Level level) {
		return ResultBean.success(levelService.update(level));
	}

	/**
	 * @Description: 根据主键更新不为默认值的字段
	 * @param level
	 * @return ResultBean<Level>
	 */
	//@PutMapping("{uniqueid}")
	@PostMapping("{uniqueid}")
	public ResultBean<Level> updatePatch(@PathVariable("uniqueid") final String uniqueid,
			final Level level) {
		return ResultBean.success(levelService.updateSelective(level));
	}

	/**
	 * @Description: 根据主键删除
	 * @param uniqueid
	 * @return ResultBean<Level>
	 */
	@DeleteMapping("{uniqueid}")
	public ResultBean<Level> delete(@PathVariable("uniqueid") final String uniqueid) {
		return ResultBean.success(levelService.delete(uniqueid));
	}

	//绑定下拉用
	@GetMapping("select2/{uniqueid}")
	@ResponseBody
	public List<Map> getSelect2Data(@PathVariable("uniqueid") final String uniqueid) {
		return levelService.getSelect2Data(uniqueid);
	} 

}
